<?php

namespace Taxx\KernelBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Doctrine\ORM\EntityManager;

class RemoteDataController extends Controller
{
    public function isSetInDatabaseAction()
    {
        if(!$this->getRequest()->isXmlHttpRequest())
            return new RedirectResponse($this->get('router')->generate('landingpage'));
   
        $entity_name = $this->getRequest()->request->get('entity');
        $entity_properties = $this->getRequest()->request->get('properties');
        
        $em = $this->get('doctrine.orm.entity_manager');
        $result = $em->getRepository("TaxxKernelBundle:".$entity_name)->findBy($entity_properties);
        
        $check_result = '0';
        if(count($result)>0)
            $check_result = '1';
        
        return new Response($check_result);
    }
 
}
